package com.common.my.controller;

import com.common.my.util.UploadUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: cmy
 * @create: 2019-03-27 12:19
 **/
@Controller
public class FileUploadController {
    @ResponseBody
    @RequestMapping("/uploadImage")
    public Map<String, Object> uploadImage(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {

        String path= UploadUtil.upload(request,file);
        Map<String, Object> map = new HashMap<>();
        map.put("src",path);

        return map;
    }
}
